package logic.nodes;

import com.jme.scene.Controller;

public abstract class BoundController extends Controller {
	
	private static final long serialVersionUID = 1L;
	
	protected ModelNode node;
	protected boolean done;
	
	public BoundController(ModelNode node) {
		this.node = node;
	}

	@Override
	public void update(float time) {
		if(!done && ready()) {
			performAction(time);
			node.getIngameState().getThreadPool().addPostRunnable(new Runnable() {
				@Override
				public void run() {
					node.removeController(BoundController.this);
				}
			});
			done = true;
		}
	}
	
	protected abstract boolean ready();
	
	protected abstract void performAction(float time);
}